package server

import (
	"gitee.com/A1001574000/feedback-rpc/feedback"
	"gitee.com/A1001574000/feedback-rpc/model"
	"gorm.io/gorm"
)

func CreateFeedback(in *feedback.UserFeedback) (*feedback.UserFeedback, error) {
	feedback := model.NewTable()
	create, err := feedback.Create(pdToMysql(in))
	if err != nil {
		return nil, err
	}
	return mysqlToPd(create)
}
func InsertImg(data *feedback.FeedbackImgRequest) {
	for _, s := range data.InsertImg.Img {
		n := model.FeedbackImg{
			UserId:      data.InsertImg.UserId,
			FeedbackImg: s,
		}
		n.Create(n)
	}
}
func mysqlToPd(in *model.Feedback) (*feedback.UserFeedback, error) {
	return &feedback.UserFeedback{
		Id:           int64(in.ID),
		UserId:       in.UserId,
		FeedbackText: in.FeedbackText,
		FeedbackType: in.FeedbackType,
		ContactWay:   in.ContactWay,
	}, nil
}
func pdToMysql(in *feedback.UserFeedback) *model.Feedback {
	return &model.Feedback{
		Model: gorm.Model{
			ID: uint(in.Id),
		},
		UserId:       in.UserId,
		FeedbackText: in.FeedbackText,
		FeedbackType: in.FeedbackType,
		ContactWay:   in.ContactWay,
	}
}
